package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.TransportPurchaseInventoryDetail;
import com.hunttown.mes.rpc.exception.ConvertException;
import com.hunttown.mes.rpc.domain.TransportPurchaseInventoryDetailDTO;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2019-12-24 15:52:03
 */
public class TransportPurchaseInventoryDetailConverts {

    private static Logger LOG = LoggerFactory.getLogger(TransportPurchaseInventoryDetailConverts.class);

    public static List<TransportPurchaseInventoryDetailDTO> convert(List<TransportPurchaseInventoryDetail> transportPurchaseInventoryDetailList) {
        if (CollectionUtils.isEmpty(transportPurchaseInventoryDetailList)) {
            return Collections.EMPTY_LIST;
        }

        List<TransportPurchaseInventoryDetailDTO> transportPurchaseInventoryDetailListResult = Lists.newArrayList();
        for (TransportPurchaseInventoryDetail transportPurchaseInventoryDetail : transportPurchaseInventoryDetailList) {
            transportPurchaseInventoryDetailListResult.add(convert(transportPurchaseInventoryDetail));
        }
        return transportPurchaseInventoryDetailListResult;
    }

    public static TransportPurchaseInventoryDetailDTO convert(TransportPurchaseInventoryDetail transportPurchaseInventoryDetail) {
        try {
            return BeanUtils.copy(transportPurchaseInventoryDetail, TransportPurchaseInventoryDetailDTO.class);
        } catch (Exception e) {
            LOG.error("TransportPurchaseInventoryDetail到TransportPurchaseInventoryDetailDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "TransportPurchaseInventoryDetail到TransportPurchaseInventoryDetailDTO转换失败", e);
        }
    }

    public static TransportPurchaseInventoryDetail convert(TransportPurchaseInventoryDetailDTO transportPurchaseInventoryDetailDTO) {
        try {
            return BeanUtils.copy(transportPurchaseInventoryDetailDTO, TransportPurchaseInventoryDetail.class);
        } catch (Exception e) {
            LOG.error("TransportPurchaseInventoryDetailDTO到TransportPurchaseInventoryDetail转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "TransportPurchaseInventoryDetailDTO到TransportPurchaseInventoryDetail转换失败", e);
        }
    }
}